package com.atguigu.gmall.order.controller;

import com.atguigu.gmall.common.execption.GmallException;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.order.dto.OrderSubmitDto;
import com.atguigu.gmall.order.service.OrderInfoService;
import com.atguigu.gmall.ware.entity.WareStockMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 数据校验的位置：
 * 1、前端
 * 2、后端(肯定是需要进行校验的)
 * 数据校验的分类：
 * 1、数据格式的校验    -----> 正则表达式
 * 2、业务逻辑的校验    -----> 编写业务代码
 */
@RestController
@RequestMapping(value = "/api/order")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService ;

    /**
     * @Valid: 开启校验功能
     * @param tradeNo
     * @param orderSubmitDto
     * @return
     */
    @PostMapping(value = "/auth/submitOrder")
    public Result<String> submitOrder(@RequestParam(value = "tradeNo") String tradeNo , @Valid @RequestBody OrderSubmitDto  orderSubmitDto) {
        String orderId = orderInfoService.submitOrder(tradeNo , orderSubmitDto) ;
        return Result.build(orderId , ResultCodeEnum.SUCCESS) ;
    }

    @PostMapping(value = "/orderSplit")
    public List<WareStockMsg> orderSplit(@RequestParam(value = "orderId") Long orderId , @RequestParam(value = "wareSkuMap") String wareSkuMap) {
        return orderInfoService.orderSplit(orderId , wareSkuMap) ;
    }

}
